package com.yt.generator.engine.config;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 控制器模板生成的配置
 *
 * @author fengshuonan
 * @date 2017-05-07 22:12
 */
@Data
public class ModelsConfig {

    private ContextConfig contextConfig;

    private String saveBOPathTemplate;
    private String boPathTemplate;
    private String dtoPathTemplate;
    private String voPathTemplate;
    private String packageBOName;//bo包名称
    private String packageDTOName;//dto包名称
    private String packageVOName;//vo包名称
    private List<String> importsSaveBO;//saveBo所导入的包
    private List<String> importsBO;//bo所引入的包
    private List<String> importsDTO;//dto所引入的包
    private List<String> importsVO;//vo所引入的包

    public void init() {
        ArrayList<String> importsSaveBO = new ArrayList<>();
        importsSaveBO.add("io.swagger.annotations.ApiModelProperty");
        importsSaveBO.add("lombok.Data");
        importsSaveBO.add("java.io.Serializable");
        this.importsSaveBO = importsSaveBO;

        ArrayList<String> importsBO = new ArrayList<>();
        importsBO.add(contextConfig.getPomGroupId()+".common.bo.BaseBO");
        importsBO.add("io.swagger.annotations.ApiModelProperty");
        importsBO.add("lombok.Data");
        importsBO.add("java.util.Date");
        importsBO.add("java.io.Serializable");
        this.importsBO = importsBO;

        ArrayList<String> importsDTO = new ArrayList<>();
        importsDTO.add("com.baomidou.mybatisplus.annotations.TableName");
        importsDTO.add("io.swagger.annotations.ApiModel");
        importsDTO.add("io.swagger.annotations.ApiModelProperty");
        importsDTO.add("lombok.Data");
        importsDTO.add("java.io.Serializable");
        importsDTO.add(contextConfig.getPomGroupId()+".common.dto.BaseDTO");


        this.importsDTO = importsDTO;

        ArrayList<String> importsVO = new ArrayList<>();
        importsVO.add("io.swagger.annotations.ApiModelProperty");
        importsVO.add("lombok.Data");
        importsVO.add("java.util.Date");
        importsVO.add("java.io.Serializable");
        this.importsVO = importsVO;

        if (StringUtils.isNotEmpty(contextConfig.getModuleName())) {
            this.packageBOName = contextConfig.getProjectBasePackageName() + ".models.bo." + contextConfig.getModuleName();
            this.packageDTOName = contextConfig.getProjectBasePackageName() + ".models.dto." + contextConfig.getModuleName();
            this.packageVOName = contextConfig.getProjectBasePackageName() + ".models.vo." + contextConfig.getModuleName();
        } else {
            this.packageBOName = contextConfig.getProjectBasePackageName() + ".models.bo";
            this.packageDTOName = contextConfig.getProjectBasePackageName() + ".models.dto";
            this.packageVOName = contextConfig.getProjectBasePackageName() + ".models.vo";
        }

        //模板生成路径
        if (StringUtils.isNotEmpty(contextConfig.getModuleName())) {
            this.saveBOPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\bo\\" + contextConfig.getModuleName() + "\\{}SaveBO.java";
            this.boPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\bo\\" + contextConfig.getModuleName() + "\\{}BO.java";
            this.dtoPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\dto\\" + contextConfig.getModuleName() + "\\{}DTO.java";
            this.voPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\vo\\" + contextConfig.getModuleName() + "\\{}VO.java";
        } else {
            this.saveBOPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\bo\\{}SaveBO.java";
            this.boPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\bo\\{}BO.java";
            this.dtoPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\dto\\{}DTO.java";
            this.voPathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\vo\\{}VO.java";
        }
    }

}
